﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Presenter_SSResourceManager;
using Model_SSResourceManager;

namespace WebView_SSResourceManager.Admin
{
    public partial class EditResource : System.Web.UI.Page, IViewManageResources
    {
        private PresenterManageResources _presenter = null;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["CollectionId"] != null)
            {
                Session.Remove("CollectionId");
            }
            _presenter = new PresenterManageResources(this);
            _presenter.LoadData();
        }

        public void SetDataForResources(IEnumerable<Resource> allResources)
        {
            lstV_ResourcesView.DataSource = allResources;
            lstV_ResourcesView.DataBind();
        }

        public void SetIdsInCollection(List<Guid> ids)
        {
            Session.Add("CollectionId", ids);
        }

        protected void LstVResourcesViewItemDeleting(object sender, ListViewDeleteEventArgs e)
        {
            var ind = lstV_ResourcesView.SelectedIndex;
            var ids = (List<Guid>)Session["CollectionId"];
            var id = ids[lstV_ResourcesView.SelectedIndex];
            _presenter.DeleteResourse(id);
            _presenter.LoadData();
        }

        protected void LstVResourcesViewSelectedIndexChanged(object sender, EventArgs e)
        {
            _presenter.LoadData();
        }

        protected void LstVResourcesViewSelectedIndexChanging(object sender, ListViewSelectEventArgs e)
        {

        }
    }
}